home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 4
/
FM Towns Free Software Collection 4 - Disc 1.iso
/
t_os
/
wstype
/
source
/
eyes.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-18
|
4KB
|
187 lines
/*** [eyes.c]
*
* 「目」ウィンドウ 関連 (C)ささがわ
*
* For GNU C Compiler (GCC) Version 1.39
*
***/
#include <stdio.h>
#include <math.h>
#include "graph.h"
#include "mos.h"
#include "window.h"
#include "icn.h"
#include "others.h"
#define WH_CAN 1
#define WH_TITLE 2
#define WH_OTHER 0
extern int PAL_Black;
static int wx, wy;
static int pex1, pey1, pex2, pey2;
static void Draw_window(void);
static int Where(int, int);
static void eye(void);
static int cal(int, int, int *, int *);
void WIND_eyes(void) {
int ret = 0;
struct RECT a, b;
wx = 205;
wy = 165;
a.x1 = 319; a.y1 = 259;
a.x2 = 320; a.y2 = 260;
b.x1 = wx; b.y1 = wy;
b.x2 = wx + 229; b.y2 = wy + 150;
afterImage(&a, &b);
Draw_window();
pex1 = 1000;
pey1 = 1000;
pex2 = 1000;
pey2 = 1000;
while (!ret) {
char mb;
int mx, my, wh;
CLOCK(0);
if (MOS_rdpos(&mb, &mx, &my), !(mb & 1)) {
eye();
continue;
}
if ((wh = Where(mx, my)) == WH_CAN) {
if (Button(wx + 6, wy + 6, wx + 25, wy + 25))
ret = 1;
} else if (wh == WH_TITLE) {
struct RECT s, w;
w.x1 = wx; w.y1 = wy;
w.x2 = wx + 229; w.y2 = wy + 150;
s.x1 = 0; s.y1 = 40; s.x2 = 639; s.y2 = 463;
if (dragWindow(mx, my, &w, &s, 0, 0)) {
wx = w.x1; wy = w.y1;
MOS_disp(0);
EGB_cls(0);
MOS_disp(1);
Draw_window();
pex1 = 1000;
pey1 = 1000;
pex2 = 1000;
pey2 = 1000;
}
} else {
while (MOS_rdpos(&mb, &mx, &my), mb & 1)
eye();
}
}
return;
}
static void Draw_window(void) {
short el[4];
struct opnwin_t opw;
opw.title = "Eyes";
opw.x1 = wx;
opw.y1 = wy;
opw.x2 = opw.x1 + 229;
opw.y2 = opw.y1 + 150;
opw.shdw = 1;
opw.canb = 1;
opw.nopt = 0;
opw.wopt = NULL;
opw.expb = 0;
opw.ord = 0;
MOS_disp(0);
drawWindow(&opw);
EGB_color(EGB_work, EGB_COL_FORE, PAL_Black);
EGB_color(EGB_work, EGB_COL_PAINT, 15);
EGB_paintMode(EGB_work, 0x022);
EGB_pen(EGB_work, 0);
EGB_penSize(EGB_work, 8);
el[0] = wx + 65;
el[1] = wy + 86;
el[2] = 40;
el[3] = 46;
EGB_ellipse(EGB_work, (char *)el);
el[0] = wx + 165;
el[1] = wy + 86;
el[2] = 40;
el[3] = 46;
EGB_ellipse(EGB_work, (char *)el);
EGB_penSize(EGB_work, 1);
MOS_disp(1);
}
static int Where(int x, int y) {
int ret;
x -= wx;
y -= wy;
if (5 < x && x < 26 && 5 < y && y < 26)
ret = WH_CAN;
else if (26 < x && x < 224 && 5 < y && y < 26)
ret = WH_TITLE;
else
ret = WH_OTHER;
return ret;
}
static void eye(void) {
int mx, my, ex, ey;
char mb;
MOS_rdpos(&mb, &mx, &my);
EGB_penSize(EGB_work, 16);
cal(mx - (wx + 65), my - (wy + 86), &ex, &ey);
if (pex1 != ex || pey1 != ey) {
MOS_disp(0);
EGB_pointset(pex1 + (wx + 65), pey1 + (wy + 86), 15);
EGB_pointset(ex + (wx + 65), ey + (wy + 86), PAL_Black);
MOS_disp(1);
pex1 = ex;
pey1 = ey;
}
cal(mx - (wx + 165), my - (wy + 86), &ex, &ey);
if (pex2 != ex || pey2 != ey) {
MOS_disp(0);
EGB_pointset(pex2 + (wx + 165), pey2 + (wy + 86), 15);
EGB_pointset(ex + (wx + 165), ey + (wy + 86), PAL_Black);
MOS_disp(1);
pex2 = ex;
pey2 = ey;
}
EGB_penSize(EGB_work, 1);
}
#define POW(x) ((x) * (x))
static int cal(int mx, int my, int *ex, int *ey) {
int ret;
float k;
if (POW((float)mx) / POW(24.0) + POW((float)my) / POW(27.6) <= 1.0) { /* 27.6 == 40 * .6 * 1.15 24 == 40 * .6 */
ret = 1;
*ex = mx;
*ey = my;
} else {
ret = 0;
k = sqrt(1.0 / (POW((float)mx / 24.0) + POW((float)my / 27.6)));
*ex = k * mx;
*ey = k * my;
}
return ret;
}
#undef POW